package com.yonder.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yonder.dao.CheckItemDao;
import com.yonder.entity.PageResult;
import com.yonder.entity.Result;
import com.yonder.pojo.CheckItem;
import com.yonder.service.CheckItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLOutput;
import java.util.List;

/**
 * @ClassName CheckItemsServiceImpl
 * @Description TODO
 * @Author zxs
 * @Date 2021/3/19 17:56
 * Version 1.0
 * 检查项业务层接口实现类
 */

@Service
@Transactional//事务
public class CheckItemsServiceImpl implements CheckItemsService {

    @Autowired
    private CheckItemDao checkItemDao;

    @Override
    public void add(CheckItem checkItem) {
//        System.out.println("CheckItemsController==========");
        checkItemDao.add(checkItem);
    }

    /*
    * 检查项分页查询
    * */
    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {

        /*
        * 这里通过 PageHelper 这个类对sql语句里面的 limit进行处理
        * */
        PageHelper.startPage(currentPage,pageSize);
        Page <CheckItem> page = checkItemDao.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void deleteById(Integer id) {
        checkItemDao.deleteById(id);
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkItemDao.edit(checkItem);
    }

    @Override
    public List<CheckItem> findAll() {
        return checkItemDao.findAll();
    }

    // add(toName) string
}
